package com.pd.backend.service.impl;

import com.pd.backend.entity.PdCoreStation;
import com.pd.backend.dao.PdCoreStationDao;
import com.pd.backend.service.PdCoreStationService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 岗位(PdCoreStation)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:33
 */
@Service("pdCoreStationService")
public class PdCoreStationServiceImpl implements PdCoreStationService {
    @Resource
    private PdCoreStationDao pdCoreStationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdCoreStation queryById(Long id) {
        return this.pdCoreStationDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdCoreStation 筛选条件
     * @param pageRequest   分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdCoreStation> queryByPage(PdCoreStation pdCoreStation, PageRequest pageRequest) {
        long total = this.pdCoreStationDao.count(pdCoreStation);
        return new PageImpl<>(this.pdCoreStationDao.queryAllByLimit(pdCoreStation, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdCoreStation 实例对象
     * @return 实例对象
     */
    @Override
    public PdCoreStation insert(PdCoreStation pdCoreStation) {
        this.pdCoreStationDao.insert(pdCoreStation);
        return pdCoreStation;
    }

    /**
     * 修改数据
     *
     * @param pdCoreStation 实例对象
     * @return 实例对象
     */
    @Override
    public PdCoreStation update(PdCoreStation pdCoreStation) {
        this.pdCoreStationDao.update(pdCoreStation);
        return this.queryById(pdCoreStation.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.pdCoreStationDao.deleteById(id) > 0;
    }
}
